<template>
  <Scroll class="wriper_right" ref="wriper">
    <div class="right">
      <div class="item" v-for="(item, index) in right_data" :key="index">
        <a :href="item.link">
          <img :src="item.image" alt="" @load="images" />
          <span>{{ item.title }}</span>
        </a>
      </div>
    </div>
  </Scroll>
</template>

<script>
import Scroll from "@/components/scroll/Scroll.vue"

export default {
  name: "Right",
  props: {
    right_data: {
      type: Array,
      default: [],
    },
  },
  components: {
    Scroll,
  },
  methods: {
    //数据更新是出触发
    images() {
      this.debounce(() => {
        this.$refs.wriper.scroll.refresh()
      }, 200)()
    },
    //封装防抖动函数
    debounce(fn, delay) {
      var timer = null // 声明计时器
      return function () {
        var context = this
        var args = arguments
        clearTimeout(timer)
        timer = setTimeout(function () {
          fn.apply(context, args)
        }, delay)
      }
    },
  },
}
</script>

<style lang="less" scoped>
.wriper_right {
  flex: 7;
  height: calc(100vh - 45px - 45px);
  .right {
    display: flex;
    flex-wrap: wrap;
    box-sizing: content-box;
    padding: 20px 8px;
    .item {
      flex-basis: 30%;
      margin-right: 8px;
      text-align: center;
      margin-bottom: 10px;
      img {
        width: 80%;
      }
      span {
        display: block;
        text-align: center;
        margin-top: 5px;
        color: #666666;
        font-size: 12px;
      }
    }
    .item:nth-of-type(3n) {
      margin-right: 0;
    }
  }
}
</style>
